//导入pinia
import type { ConsultType } from '@/enums'
import type { ConsultIllness } from '@/types/consult'
import type { PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    //保存数据
    const consult = ref<PartialConsult>({})

    //定义保存数据的方法
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    //问诊类型 三甲还是普通
    const setIllness = (type: 0 | 1) => {
      consult.value.illnessType = type
    }

    //保存科室id
    const setDeptId = (id: string) => {
      consult.value.depId = id
    }

    //保存病情描述
    const setIllnessDesc = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    //保存患者id
    const setIllnessId = (id: string) => {
      consult.value.patientId = id
    }

    //保存优惠券id
    const setCoupon = (id: string) => {
      consult.value.couponId = id
    }

    //清空患者信息
    const clear = () => (consult.value = {})

    return {
      consult,
      setType,
      setIllness,
      setDeptId,
      setIllnessDesc,
      setIllnessId,
      setCoupon,
      clear
    }
  },
  {
    persist: true
  }
)
